<template>
    <van-sticky>
        <van-nav-bar title="分类" left-text="返回" left-arrow @click-left="onClickLeft" />
    </van-sticky>
    <div class="zuo">
        <van-sidebar v-model="active">
            <van-sidebar-item v-for="(item, index) in arr" :key="index" :title="item.cat_name" />
        </van-sidebar>
    </div>
    <div>
        <li v-for="(item, index) in arr[active]?.children" :key="index">{{ item.cat_name }}
            <van-grid :column-num="3">
                <van-grid-item v-for="(items, index) in item.children" :key="index" :icon="items.cat_icon" :text="items.cat_name" @click="t(items.cat_id)"/>
            </van-grid>
        </li>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let router = new useRouter()
const onClickLeft = () => history.back();
const active = ref(0);
let arr = ref([])
axios.get('https://api-hmugo-web.itheima.net/api/public/v1/categories').then(res => {
    arr.value = res.data.message
})
const t = (cid)=>{
    router.push({
        path: '/xq',
        query: {
            // url的参数, 类似get请求的传参
            cid
        },
    })
}
</script>

<style>
.zuo {
    float: left;
}
</style>